package com.example.ScrollDemo;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class MyActivity extends Activity implements MyScrollView.OnScrollListener {

    private View titleBar;
    private TextView textView;

    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        MyScrollView scrollView = (MyScrollView) findViewById(R.id.scroll_view);
        titleBar = findViewById(R.id.title_bar);
        textView = (TextView) findViewById(R.id.title);
        scrollView.setOnScrollListener(this);

    }

    @Override
    public void onScroll(int scrollY) {
        float alpha = titleBar.getAlpha();
        textView.setText(String.valueOf(alpha));
        if (scrollY > 220){ // 220 - 520 0.5
            titleBar.setAlpha(0.5f + (scrollY - 220) / 600.f);
        }else {
            titleBar.setAlpha(0);
        }
    }
}
